package com.tttn.docbao.adapter;

import java.util.ArrayList;
import java.util.zip.Inflater;

import com.tttn.docbao.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SplashAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<String> data = new ArrayList<String>();

	public SplashAdapter(Context context, ArrayList<String> data) {
		this.context = context;
		this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public ArrayList<Integer> getIcon() {
		ArrayList<Integer> name = new ArrayList<Integer>();
		name.add(R.drawable.icon_dantri);
		name.add(R.drawable.icon_vnexpress);
		name.add(R.drawable.icon_24h);
		return name;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = new ViewHolder();
		View view = convertView;
		if (view == null) {
			LayoutInflater inflate = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflate.inflate(R.layout.layout_lvnews, null);
			vh.imvicon = (ImageView) view.findViewById(R.id.imvNews);
			vh.tvname = (TextView) view.findViewById(R.id.txtName);
			view.setTag(vh);
		} else {
			vh = (ViewHolder) view.getTag();
		}
		vh.tvname.setText((String) getItem(position));
		vh.imvicon.setImageResource(getIcon().get(position));
		return view;
	}

	static class ViewHolder {
		ImageView imvicon;
		TextView tvname;
	}

}
